********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

****
** Cross sectional analyses
****

set more off

* SET WORKING DIRECTORY

********************************************************************************

*** 2016 ANES TIME SERIES Study ***

use "anes_timeseries_2016_Stata12.dta"

****
** Clean/recode variables
****

* Case ID
gen caseid = V160001


* Year 
gen year = 2016

gen yearalt1 = 7


* Weight
gen weight = V160101


* Internet
gen internet = 0
replace internet = 1 if V160501 == 2


* Feeling thermometers
gen trumptherm = V161087
replace trumptherm = . if trumptherm < 0
replace trumptherm = . if trumptherm > 100
recode trumptherm (100=97) (99=97) (98=97)

gen clintontherm = V161086
replace clintontherm = . if clintontherm < 0
replace clintontherm = . if clintontherm > 100
recode clintontherm (100=97) (99=97) (98=97)

gen liberaltherm = V162097
replace liberaltherm = . if liberaltherm < 0
replace liberaltherm = . if liberaltherm > 100
recode liberaltherm (100=97) (99=97) (98=97)

gen conservtherm = V162101
replace conservtherm = . if conservtherm < 0
replace conservtherm = . if conservtherm > 100
recode conservtherm (100=97) (99=97) (98=97)

gen dempartytherm = V161095
replace dempartytherm = . if dempartytherm < 0
replace dempartytherm = . if dempartytherm > 100
recode dempartytherm (100=97) (99=97) (98=97)

gen reppartytherm = V161096
replace reppartytherm = . if reppartytherm < 0
replace reppartytherm = . if reppartytherm > 100
recode reppartytherm (100=97) (99=97) (98=97)


gen partythermdiff = abs(dempartytherm - reppartytherm)

gen diffcandtherm = abs(clintontherm - trumptherm)

gen ideothermdiff = abs(liberaltherm - conservtherm)


* Party identification
gen pid = V161158x
replace pid = . if pid < 1
replace pid = pid - 4

gen rep = 1 if pid > 0
replace rep = 0 if pid < 0

gen pidstrength = abs(pid)


* Ideology
gen ideo = V162171
replace ideo = . if ideo < 1
replace ideo = . if ideo > 7
replace ideo = ideo - 4

gen conserv = 1 if ideo > 0
replace conserv = 0 if ideo < 0

gen ideostrength = abs(ideo)


* Partisan sorting (ala Mason 2015)
replace ideostrength = ideostrength + 1
replace pidstrength = pidstrength + 1
gen sorting = abs(pid - (-1 * ideo)) * ideostrength * pidstrength


* Church attendance
gen church = V161245
replace church = . if church > 5
replace church = . if church < 1
recode church (5=1) (4=2) (3=3) (2=4) (1=5)


* Interest in following campaign
gen interest = V161004
replace interest = . if V161004 < 1
recode interest (1=2) (2=1) (3=0)


* Retrospective economic evaluations
gen econeval = V161140
replace econeval = . if V161140 < 1
recode econeval (3=0) (2=1) (1=2)


* Race
gen white = 1 if V161310x == 1
replace white = 0 if V161310x != 1

gen black = 1 if V161310x == 2
replace black = 0 if V161310x != 2

gen hispanic = 1 if V161310x == 5
replace hispanic = 0 if V161310x != 5


* Do whatever is necessary for equal opportunity
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen equalopp = V162243 - 1
replace equalopp = . if equalopp < 0


*Big problem is not giving everyone an equal chance
gen equalchance = V162245
replace equalchance = . if equalchance < 1
recode equalchance (5=0) (4=1) (3=2) (2=3) (1=4)


* Better off if we worried less about equality
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen lessequal = V162244
replace lessequal = . if lessequal < 1
recode lessequal (5=0) (4=1) (3=2) (2=3) (1=4)


* Many fewer problems if people were treated equally
gen fewer = V162246 - 1
replace fewer = . if fewer < 0


*Adjusting views of moral behavior
gen changing = V162207 - 1
replace changing = . if changing < 0
 
 
* Newer lifestyles contributing to a breakdown in society
* Note: This variable is reverse coded so that higher values indicate*
* more conservative attitudes
gen lifestyles = V162208
replace lifestyles = . if lifestyles < 1
recode lifestyles (5=0) (4=1) (3=2) (2=3) (1=4)


* Tolerant of people who choose to live according to their own moral standards
gen standards = V162209 - 1
replace standards = . if standards < 0
 
 
* More emphasis on traditional family ties*
* Note: This variable is reverse coded so that higher values indicate
* more conservative attitudes
gen family = V162210
replace family = . if family < 1
recode family (5=0) (4=1) (3=2) (2=3) (1=4)


* Creating values scales
alpha equalopp equalchance lessequal fewer changing lifestyles standards ///
	family, detail item generate(values) casewise

alpha equalopp equalchance lessequal fewer, detail item ///
	generate(equality) casewise
	
alpha changing lifestyles standards family, detail item ///
	generate(morality) casewise


* Party placement on ideological scale
gen demideo = V161130
replace demideo = . if demideo > 7
replace demideo = . if demideo < 1
recode demideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen repideo = V161131
replace repideo = . if repideo > 7
replace repideo = . if repideo < 1
recode repideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen diffideoplace = abs(demideo - repideo)


* Candidate placement on ideological scale
gen dcandideo = V161128
replace dcandideo = . if dcandideo > 7
replace dcandideo = . if dcandideo < 1
recode dcandideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen rcandideo = V161129
replace rcandideo = . if rcandideo > 7
replace rcandideo = . if rcandideo < 1
recode rcandideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen diffcandideo = abs(dcandideo - rcandideo)	


* Self and candidate placement on guaranteed jobs scale 
gen selfjobs = V161189
replace selfjobs = . if selfjobs < 1
replace selfjobs = . if selfjobs >= 8
recode selfjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define jobslab -3 "Government see to job and good standard of living" ///
	3 "Government let each person get ahead on his own"
label values selfjobs jobslab

gen demjobs = V161190
replace demjobs = . if demjobs < 1
replace demjobs = . if demjobs >= 8
recode demjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demjobs jobslab

gen repjobs = V161191
replace repjobs = . if repjobs < 1
replace repjobs = . if repjobs >= 8
recode repjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repjobs jobslab

gen pdiffjobs = abs(demjobs - repjobs)


* Self and candidate placement on aid to blacks scale 
gen selfaid = V161198
replace selfaid = . if selfaid < 1
replace selfaid = . if selfaid >= 8
recode selfaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define aidlab -3 "Government should help minority groups" ///
	3 "Minority groups should help themselves"
label values selfaid aidlab

gen demaid = V161199
replace demaid = . if demaid < 1
replace demaid = . if demaid >= 8
recode demaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demaid aidlab

gen repaid = V161200
replace repaid = . if repaid < 1
replace repaid = . if repaid >= 8
recode repaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repaid aidlab

gen pdiffaid = abs(demaid - repaid)


* Self and candidate placement on government services scale 
gen selfservice = V161178
replace selfservice = . if selfservice < 1
replace selfservice = . if selfservice >= 8
recode selfservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label define servicelab -3 "Government should provide many more services" ///
	3 "Government should provide many ewer services"
label values selfservice servicelab

gen demservice = V161179
replace demservice = . if demservice < 1
replace demservice = . if demservice >= 8
recode demservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label values demservice servicelab

gen repservice = V161180
replace repservice = . if repservice < 1
replace repservice = . if repservice >= 8
recode repservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label values repservice servicelab

gen pdiffservice = abs(demservice - repservice)


* Self and candidate placement on defense spending scale 
gen selfdefense = V161181
replace selfdefense = . if selfdefense < 1
replace selfdefense = . if selfdefense >= 8
recode selfdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define defenselab -3 "Greatly decrease defense spending" ///
	3 "Greatly increase defense spending"
label values selfdefense defenselab

gen demdefense = V161182
replace demdefense = . if demdefense < 1
replace demdefense = . if demdefense >= 8
recode demdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demdefense defenselab

gen repdefense = V161183
replace repdefense = . if repdefense < 1
replace repdefense = . if repdefense >= 8
recode repdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repdefense defenselab

gen pdiffdefense = abs(demdefense - repdefense)


* Self and candidate placement on government health insurance scale
gen selfinsure = V161184
replace selfinsure = . if selfinsure < 1
replace selfinsure = . if selfinsure >= 8
recode selfinsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define insurelab -3 "Government insurance plan" 3 "Private insurance plan"
label values selfinsure insurelab

gen deminsure = V161185
replace deminsure = . if deminsure < 1
replace deminsure = . if deminsure >= 8
recode deminsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values deminsure insurelab

gen repinsure = V161186
replace repinsure = . if repinsure < 1
replace repinsure = . if repinsure >= 8
recode repinsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repinsure insurelab

gen pdiffinsure = abs(deminsure - repinsure)


* Issue extremity
gen issextreme = (abs(selfdefense - 0) + abs(selfservice - 0) ///
	+ abs(selfaid - 0) + abs(selfinsure - 0) + abs(selfjobs - 0))/ 5

gen issex1 = abs(selfdefense - 0)
gen issex2 = abs(selfservice - 0)	
gen issex3 = abs(selfaid - 0)	
gen issex4 = abs(selfinsure - 0)	
gen issex5 = abs(selfjobs - 0)	
	
alpha issex1-issex5, gen(issextremealt)


* Income (recoded into percentiles based on 2016 CPS data)
gen income = V161361x
replace income = . if V161361x < 1
recode income (1=1) (2=1) (3=1) (4=1) (5=2) (6=2) (7=2) (8=2) ///
	(9=3) (10=3) (11=3) (12=3) (13=3) (14=3) (15=3) (16=4) (17=4) ///
	(18=4) (19=4) (20=4) (21=4) (22=4) (23=4) (24=4) (25=4) (26=5) ///
	(27=5) (28=5)


* Education
gen edu = V161270 
replace edu = . if edu < 1
replace edu = . if edu > 16
recode edu (1=1) (2=1) (3=1) (4=1) (5=2) (6=2) (7=2) (8=2) ///
	(9=3) (9=3) (10=4) (11=4) (12=4) (13=5) (14=6) (15=6) (16=6)

	
* Age
gen age = V161267
replace age = . if V161267 < 18


* Gender
gen female = V161342 - 1
replace female = . if female > 1
replace female = . if female < 0


* Region 
gen south = 0
replace south = 1 if V161330 == 1 | V161330 == 5 | V161330 == 12 | V161330 == 13 ///
	| V161330 == 21 | V161330 == 22 | V161330 == 28 | V161330 == 29 | V161330 == 37 ///
	| V161330 == 40 | V161330 == 45 | V161330 == 47 | V161330 == 48 | V161330 == 51 ///
	| V161330 == 54


keep caseid pid year-south

*save "Value Pol 2016.dta"

clear


********************************************************************************

*** 2012 ANES Cumulative File ***

use "anes_timeseries_cdf.dta"

****
** Clean/recode variables
****

* Create ID and year identifiers
gen caseid = VCF0006

gen year = VCF0004

drop if year < 1988
drop if year == 1990 | year == 1994 | year == 1998 | year == 2002

gen yearalt1 = 0 if year == 1988 
replace yearalt1 = 1 if year == 1992
replace yearalt1 = 2 if year == 1996
replace yearalt1 = 3 if year == 2000
replace yearalt1 = 4 if year == 2004
replace yearalt1 = 5 if year == 2008
replace yearalt1 = 6 if year == 2012

gen year1988 = 0
replace year1988 = 1 if year == 1988
gen year1992 = 0
replace year1992 = 1 if year == 1992
gen year1996 = 0
replace year1996 = 1 if year == 1996
gen year2000 = 0
replace year2000 = 1 if year == 2000
gen year2004 = 0
replace year2004 = 1 if year == 2004
gen year2008 = 0
replace year2008 = 1 if year == 2008
gen year2012 = 0
replace year2012 = 1 if year == 2012


* Survey weights
gen weight = VCF0009x


* Survey mode
gen svymode = VCF0017

gen internet = 0
replace internet = 1 if VCF0017 == 4 & year == 2012
	
	
* Self ideology (recoded to range -3-3; -2 Havent thought, -8 DK, -9 NA)
gen ideo = VCF0803
replace ideo = . if ideo < 1 
replace ideo = . if ideo == 9 
recode ideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define ideolab -3 "Ex. Liberal" -2 "-2" -1 "-1" 0 "Moderate" ///
	1 "1" 2 "2" 3 "Ex. Conservative" 
label values ideo ideolab

gen conserv = 1 if ideo > 1
replace conserv = 0 if ideo < -1


* Strength of ideological predisposition
gen ideostrength = 0 if ideo == 0
replace ideostrength = 1 if ideo == -1
replace ideostrength = 1 if ideo == 1
replace ideostrength = 2 if ideo == -2
replace ideostrength = 2 if ideo == 2
replace ideostrength = 3 if ideo == -3
replace ideostrength = 3 if ideo == -3


* Self party ID (recoded to range -3-3; -2 DK NA)
gen pid = VCF0301 
replace pid = . if pid == 0
recode pid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define partylab -3 "Strong Democrat" -2 "-2" -1 "-1" 0 "Independent" ///
	1 "1" 2 "2" 3 "Strong Republican"
label values pid partylab

gen rep = 1 if pid > 1 
replace rep = 0 if pid < -1


* Strength of ideological predisposition
gen pidstrength = 0 if pid == 0
replace pidstrength = 1 if pid == -1
replace pidstrength = 1 if pid == 1
replace pidstrength = 2 if pid == -2
replace pidstrength = 2 if pid == 2
replace pidstrength = 3 if pid == -3
replace pidstrength = 3 if pid == -3


* Education (ranges from 1-7)
gen edu = VCF0140a
replace edu = . if edu >= 8
label define edulab 1 "8 grades or less" 2 "9-12 grades" 3 "High school" ///
	4 "HS + non-academic training" 5 "Some college" 6 "BA" 7 "Advanced"
label values edu edulab


* Race 
gen race = VCF0105a
replace race = . if race == 9

gen black = 1 if race == 2
replace black = 0 if race != 2 & race != .

gen hispanic = 1 if race == 5
replace hispanic = 0 if race != 5 & race != .


* Gender (1=female)
gen gender = VCF0104
replace gender = . if gender < 1
gen female = 1 if gender == 2
recode female (.=0)
label define genderlab 0 "Male" 1 "Female"
label values female genderlab


* Age (number of years) 
gen age = VCF0101
replace age = . if age == 00


* Region
gen south = .
replace south = 0 if VCF0112 == 1
replace south = 0 if VCF0112 == 2
replace south = 0 if VCF0112 == 4
replace south = 1 if VCF0112 == 3
label var south "South Region Dummy"
label define southern 0 "0 Non-South" 1 "1 South"
label values south southern


* Income (1-6, percentiles)
gen income = VCF0114
replace income = . if income == 0


* Church attendance
gen church = VCF0130
replace church = . if church > 5
replace church = . if church < 1
recode church (5=1) (4=2) (3=3) (2=4) (1=5)


* Trust (0=Never - 3=Just about always)
gen trust = VCF0604 - 1
replace trust = . if trust > 3
replace trust = . if trust < 0

 
* Number of party likes/dislikes (0 - 5 likes)
gen demlike = VCF0314
replace demlike = . if demlike == 9

gen demdislike = VCF0315
replace demdislike = . if demdislike == 9

gen replike = VCF0318
replace replike = . if replike == 9

gen repdislike = VCF0319
replace repdislike = . if repdislike == 9

gen difflike = abs(demlike - replike)

gen diffdislike = abs(demdislike - repdislike)


* Anger toward president (1=yes)
gen angerd = VCF0358
replace angerd = . if VCF0358 > 2
replace angerd = . if VCF0358 < 1
recode angerd (2=0)

gen angerr = VCF0370
replace angerr = . if VCF0370 > 2
replace angerr = . if VCF0370 < 1
recode angerr (2=0)

gen anger = angerd if pid < 0
replace anger = angerr if pid > 0


* Perceived difference between parties (1=yes)
gen perceivediff = VCF0501 - 1
replace perceivediff = . if VCF0501 > 2
replace perceivediff = . if VCF0501 < 1


* Feeling thermometers
gen liberaltherm = VCF0211
replace liberaltherm = . if liberaltherm >= 98

gen conservtherm = VCF0212
replace conservtherm = . if conservtherm >= 98

gen ideothermdiff = abs(liberaltherm - conservtherm)


gen dempartytherm = VCF0218
replace dempartytherm = . if dempartytherm >= 98

gen reppartytherm = VCF0224
replace reppartytherm = . if reppartytherm >= 98

gen partythermdiff = abs(dempartytherm - reppartytherm)


gen demcandtherm = VCF0424
replace demcandtherm = . if demcandtherm >= 98

gen repcandtherm = VCF0426
replace repcandtherm = . if repcandtherm >= 98

gen diffcandtherm = abs(demcandtherm - repcandtherm)


* Party placement on ideological scale
gen demideo = VCF0503
replace demideo = . if demideo == 0
replace demideo = . if demideo == 8
recode demideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demideo ideolab

gen repideo = VCF0504
replace repideo = . if repideo == 0
replace repideo = . if repideo == 8
recode repideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repideo ideolab

gen diffideoplace = abs(demideo - repideo)


* Candidate placement on ideological scale
gen dcandideo = VCF9088
replace dcandideo = . if dcandideo < 1
replace dcandideo = . if dcandideo >= 8
recode dcandideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values dcandideo ideolab

gen rcandideo = VCF9089
replace rcandideo = . if rcandideo < 1
replace rcandideo = . if rcandideo >= 8
recode rcandideo (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values rcandideo ideolab

gen diffcandideo = abs(dcandideo - rcandideo)


* Partisan sorting (ala Mason 2015)
replace ideostrength = ideostrength + 1
replace pidstrength = pidstrength + 1
gen sorting = abs(pid - (-1 * ideo)) * ideostrength * pidstrength


* Self and candidate placement on guaranteed jobs scale 
gen selfjobs = VCF0809
replace selfjobs = . if selfjobs < 1
replace selfjobs = . if selfjobs >= 8
recode selfjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define jobslab -3 "Government see to job and good standard of living" ///
	3 "Government let each person get ahead on his own"
label values selfjobs jobslab

gen demjobs = VCF9087
replace demjobs = . if demjobs < 1
replace demjobs = . if demjobs >= 8
recode demjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demjobs jobslab

gen repjobs = VCF9095
replace repjobs = . if repjobs < 1
replace repjobs = . if repjobs >= 8
recode repjobs (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repjobs jobslab

gen pdiffjobs = abs(demjobs - repjobs)


* Self and candidate placement placement on aid to blacks scale 
gen selfaid = VCF0830
replace selfaid = . if selfaid < 1
replace selfaid = . if selfaid >= 8
recode selfaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define aidlab -3 "Government should help minority groups" ///
	3 "Minority groups should help themselves"
label values selfaid aidlab
 
gen demaid = VCF9084
replace demaid = . if demaid < 1
replace demaid = . if demaid >= 8
recode demaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demaid aidlab

gen repaid = VCF9092
replace repaid = . if repaid < 1
replace repaid = . if repaid >= 8
recode repaid (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repaid aidlab

gen pdiffaid = abs(demaid - repaid)


* Self and candidate placement placement on government services scale 
gen selfservice = VCF0839
replace selfservice = . if selfservice < 1
replace selfservice = . if selfservice >= 8
recode selfservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label define servicelab -3 "Government should provide many more services" ///
	3 "Government should provide many ewer services"
label values selfservice servicelab

gen demservice = VCF9086
replace demservice = . if demservice < 1
replace demservice = . if demservice >= 8
recode demservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label values demservice servicelab

gen repservice = VCF9094
replace repservice = . if repservice < 1
replace repservice = . if repservice >= 8
recode repservice (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label values repservice servicelab

gen pdiffservice = abs(demservice - repservice)


* Self and candidate placement placement on defense spending scale 
gen selfdefense = VCF0843
replace selfdefense = . if selfdefense < 1
replace selfdefense = . if selfdefense >= 8
recode selfdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define defenselab -3 "Greatly decrease defense spending" ///
	3 "Greatly increase defense spending"
label values selfdefense defenselab

gen demdefense = VCF9081
replace demdefense = . if demdefense < 1
replace demdefense = . if demdefense >= 8
recode demdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values demdefense defenselab

gen repdefense = VCF9089
replace repdefense = . if repdefense < 1
replace repdefense = . if repdefense >= 8
recode repdefense (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repdefense defenselab

gen pdiffdefense = abs(demdefense - repdefense)


* Self and candidate placement on government health insurance scale
gen selfinsure = VCF0806
replace selfinsure = . if selfinsure < 1
replace selfinsure = . if selfinsure >= 8
recode selfinsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define insurelab -3 "Government insurance plan" 3 "Private insurance plan"
label values selfinsure insurelab

gen deminsure = VCF9085
replace deminsure = . if deminsure < 1
replace deminsure = . if deminsure >= 8
recode deminsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values deminsure insurelab

gen repinsure = VCF9093
replace repinsure = . if repinsure < 1
replace repinsure = . if repinsure >= 8
recode repinsure (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label values repinsure insurelab

gen pdiffinsure = abs(deminsure - repinsure)


* Issue extremity
gen issextreme = (abs(selfdefense - 0) + abs(selfservice - 0) ///
	+ abs(selfaid - 0) + abs(selfinsure - 0) + abs(selfjobs - 0))/ 5

gen issex1 = abs(selfdefense - 0)
gen issex2 = abs(selfservice - 0)	
gen issex3 = abs(selfaid - 0)	
gen issex4 = abs(selfinsure - 0)	
gen issex5 = abs(selfjobs - 0)	
	
alpha issex1-issex5, gen(issextremealt)


* Do whatever is necessary for equal opportunity (reverse coded)
gen equalopp = VCF9013 - 1
replace equalopp = . if equalopp > 4


* Have gone too far pushing equal rights (reverse coded)
gen equalrights = VCF9014
replace equalrights = . if equalrights > 5
recode equalrights (5=0) (4=1) (3=2) (2=3) (1=4)


* Big problem is not giving everyone an equal chance
gen equalchance = VCF9015 - 1
replace equalchance = . if equalchance > 4


* Better off if we worried less about equality (reverse coded)
gen lessequal = VCF9017
replace lessequal = . if lessequal > 5
recode lessequal (5=0) (4=1) (3=2) (2=3) (1=4)


* Not that big of a problem if people have more of a chance (reverse coded)
gen unequal = VCF9016
replace unequal = . if unequal > 5
recode unequal (5=0) (4=1) (3=2) (2=3) (1=4)


* Many fewer problems if people were treated equally
gen fewer = VCF9018 - 1
replace fewer = . if fewer > 4


* Adjusting views of moral behavior
gen changing = VCF0852 - 1
replace changing = . if changing > 4
 
 
* Newer lifestyles contributing to a breakdown in society (reverse coded)
gen lifestyles = VCF0851
replace lifestyles = . if lifestyles > 5
recode lifestyles (5=0) (4=1) (3=2) (2=3) (1=4)


* Tolerant of people who choose to live according to their own moral standards
gen standards = VCF0854 - 1
replace standards = . if standards > 4
 
 
* More emphasis on traditional family ties (reverse coded)
gen family = VCF0853
replace family = . if family > 5
recode family (5=0) (4=1) (3=2) (2=3) (1=4)


* Creating values scales
factor equalopp equalchance lessequal fewer changing lifestyles standards ///
	family, ipf

alpha equalopp equalchance lessequal fewer changing lifestyles standards ///
	family, detail item generate(values) casewise
	
sem (Values -> equalopp-family), method(mlmv) latent(Values) nocapslatent
predict valuefac, latent	

alpha equalopp equalchance lessequal fewer, ///
	detail item generate(equality) casewise

alpha changing lifestyles standards family, detail item ///
	generate(morality) casewise
	
gen valuediff = equality - morality	
gen absvaluediff = abs(valuediff)


* Vote choice
gen prezvote = VCF0704
replace prezvote = . if prezvote == 0
label define prezvotelab 1 "Democrat" 2 "Republican" 3 "Third party"
label values prez prezvotelab

gen congvote = VCF0707
replace congvote = . if congvote == 0
label define votelab 1 "Democrat" 2 "Republican"
label values congvote votelab

gen senvote = VCF0708
replace senvote = . if senvote == 0
label values senvote votelab


* Level of information, as assessed by interviewer
gen info = VCF0050a
replace info = . if info == 9
recode info (1=5) (2=4) (3=3) (4=2) (1=5)
label define infolab 1 "Very low" 2 "Fairly Low" 3 "Average" ///
	4 "Fairly High" 5 "Very High"
label values info infolab


* Interest in campaigns (1 Hardly at all - 4 Most of the time)
gen interest = VCF0310
replace interest = . if VCF0310 == 0
replace interest = . if VCF0310 == 9
label var interest "Interest in the the Campaigns"
label define interestlab 1 "Not much interested" ///
	2 "Somewhat interested" 3 "Very much interested"
label values interest interestlab


* External efficacy index (0 Least efficacious - 100 Most efficacious)
gen efficacy = VCF0648
replace efficacy = . if efficacy == 999


* Participation index (1 Lowest - 6 Highest)
gen participate = VCF0723
replace participate = . if participate == 0


* Media exposure index (1 No media - 5 All four media)
gen media = VCF0728
replace media = . if media == 0


* Sophistication scale (all years but 1994)
factor info participate, factor(1) ipf
predict sophscale

gen sophscale94 = interest + participate
replace sophscale = sophscale94 if year == 1994


* Difference in party mean DW-NOMINATE scores
gen housepol = 0.492 if year == 1972
replace housepol = 0.499 if year == 1976
replace housepol = 0.489 if year == 1978
replace housepol = 0.514 if year == 1980
replace housepol = 0.540 if year == 1982
replace housepol = 0.573 if year == 1984
replace housepol = 0.618 if year == 1988
replace housepol = 0.634 if year == 1990
replace housepol = 0.664 if year == 1992
replace housepol = 0.727 if year == 1994
replace housepol = 0.818 if year == 1996
replace housepol = 0.877 if year == 2000
replace housepol = 0.942 if year == 2004
replace housepol = 0.994 if year == 2008
replace housepol = 1.065 if year == 2012
replace housepol = 1.076 if year == 2016

keep caseid-housepol


append using "Value Pol 2016.dta"


********************************************************************************

****
** Analyses
****

* Generate value polarization variable
gen valuepold = .
gen valuepolr = .	
	
sum values if values != . & rep == 1, meanonly
replace valuepold = values - r(mean) if values != . & rep == 0
sum values if values != . & rep == 0, meanonly
replace valuepolr = values - r(mean) if values != . & rep == 1

gen valuepoldabs = abs(valuepold)
gen valuepolrabs = abs(valuepolr)
egen valuepol = rowmax(valuepoldabs valuepolrabs)


* "Raw" value polarization (R1's request)
sum values if values != . & rep == 1, meanonly
gen valuepoldalt = r(mean) - values if values != . & rep == 0
egen valuepolalt = rowmax(valuepoldalt valuepolr)


* Intra-party value extremity (R1's request)
sum values if values != . & rep == 1, meanonly
gen intravaluer = values - r(mean) if values != . & rep == 1
sum values if values != . & rep == 0, meanonly
gen intravalued = r(mean) - values if values != . & rep == 0

egen valueextreme = rowmax(intravaluer intravalued)


* Rescale 0-1
foreach v of var valuepol partythermdiff ideothermdiff difflike diffdislike ///
diffcandtherm diffideoplace diffcandideo sorting edu income church ///
housepol age interest issextreme issextremealt ///
pidstrength ideostrength valuepolalt valueextreme{ 
	su `v', meanonly 
	gen `v'2 = (`v' - r(min))/(r(max) - r(min)) 
}
   
****
** Table 1 estimates
****

reg partythermdiff2 valuepol2 sorting2 issextremealt2 interest2 church2 ///
	income2 edu2 age2 female black hispanic south i.year, beta
est store mod1	
	
reg ideothermdiff2 valuepol2 sorting2 issextremealt2 interest2 church2 ///
	income2 edu2 age2 female black hispanic south i.year, beta
est store mod2	
	
reg diffcandtherm2 valuepol2 sorting2 issextremealt2 interest2 church2 ///
	income2 edu2 age2 female black hispanic south i.year, beta
est store mod3		
	   
estout mod1 mod2 mod3, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))
   
****
** Estimates used to produce Figure 1
** (See "Figures.r" for code)
****

reg partythermdiff2 c.valuepol2##c.yearalt1 sorting2 issextremealt2 ///
	interest2 church2 income2 edu2 age2 female black hispanic south, beta 
est store mod4		
margins, dydx(valuepol2) at(c.yearalt1=(0(1)7))

reg ideothermdiff2 c.valuepol2##c.yearalt1 sorting2 issextremealt2 ///
	interest2 church2 income2 edu2 age2 female black hispanic south, beta
est store mod5		
margins, dydx(valuepol2) at(c.yearalt1=(0(1)7))
	
reg diffcandtherm2 c.valuepol2##c.yearalt1 sorting2 issextremealt2 ///
	interest2 church2 income2 edu2 age2 female black hispanic south, beta 
est store mod6		
margins, dydx(valuepol2) at(c.yearalt1=(0(1)7))
	
estout mod4 mod5 mod6, cells(b(star fmt(3)) se(par fmt(3))) ///
   legend label varlabels(_cons constant) stats(r2 N, fmt(3 0 1))
	

*saveold "values-polarization2.dta", replace version(12)		

clear
